package com.example.hy2110szyx.service.impl;

import com.example.hy2110szyx.entity.UserInfo;
import com.example.hy2110szyx.repository.UserMapper;
import com.example.hy2110szyx.service.UserService;
import com.example.hy2110szyx.vo.PageVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserInfo queryByUno(String uno) {
        return userMapper.queryByUno(uno);
    }

    @Override
    public UserInfo queryByUsername(String username) {
        return userMapper.queryByUsername(username);
    }

    @Override
    public void regist(UserInfo user) {
        userMapper.insertOne(user);
    }

    @Override
    public Page<UserInfo> queryAllUsersForPage(PageVo<UserInfo> pageVo) {
        Page<UserInfo> page = PageHelper.startPage(pageVo.getStart(), pageVo.getMax(),
                pageVo.getOrderBy() + " " + pageVo.getOrder());
        userMapper.queryAllConn(pageVo.getCondition());
        return page;
    }

    /**
     * 修改一个用户
     * @param userInfo
     */
    @Override
    public void modOne(UserInfo userInfo) {
        userMapper.updateIfNecessary(userInfo);
    }

    /**
     * 根据id批量删除用户
     * @param ids
     */
    @Override
    public void deleteSomeById(Integer[] ids) {
        userMapper.deleteSomeById(ids);
    }
    /**
     * 根据id修改角色权限
     * @param id
     * @param role
     */
    @Override
    public void modRoleById(Integer id, Integer role) {
        userMapper.modRoleById(id, role);
    }

}
